package com.nav.backend.controller;

import com.nav.backend.pojo.*;
import com.nav.backend.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * HistoryController 搜索历史控制器类，处理与搜索历史相关的请求
 *
 * @author xiukira
 */
@RestController
@RequestMapping("/history")
public class HistoryController {
    @Autowired
    private HistoryService historyService;

    /**
     * 获取所有起终点搜索历史
     *
     * @return 所有起终点搜索历史列表
     */
    @GetMapping("/twoPoint/listAll")
    public List<TwoPointsSearch> twoPointListAll(@RequestParam String account) {
        System.out.println("调用获取所有起终点搜索历史成功");
        List<TwoPointsSearch> twoPointsSearches = historyService.twoPointListAll(account);
        for (TwoPointsSearch cc : twoPointsSearches) {
            System.out.println(cc.getSearch_origin());
            System.out.println(cc.getSearch_destination());
        }
        return twoPointsSearches;
    }

    /**
     * 删除起终点搜索历史
     *
     * @return 删除起终点搜索历史的结果
     */
    @DeleteMapping("/twoPoint/delete")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String twoPointDelete(@RequestBody TwoPointsSearch twoPointsSearch) {
        System.out.println(twoPointsSearch.getTwo_points_search_id());
        System.out.println("调用删除起终点搜索历史接口成功");
        historyService.twoPointDelete(twoPointsSearch.getTwo_points_search_id());
        return "";
    }

    /**
     * 清空起终点搜索历史
     *
     * @return 清空起终点搜索历史的结果
     */
    @DeleteMapping("/twoPoint/deleteAll")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String twoPointDeleteAll(@RequestBody User user) {
        System.out.println("调用清空起终点搜索历史接口成功");
        historyService.twoPointDeleteAll(user.getAccount());
        return "";
    }

    /**
     * 获取所有环形搜索历史
     *
     * @return 所有环形搜索历史列表
     */
    @GetMapping("/ring/listAll")
    public List<RingSearch> ringListAll(@RequestParam String account) {
        System.out.println("调用获取所有环形搜索历史成功");
        List<RingSearch> ringSearches = historyService.ringListAll(account);
        for (RingSearch cc : ringSearches) {
            System.out.println(cc.getRing_search_location());
        }
        return ringSearches;
    }

    /**
     * 删除环形搜索历史
     *
     * @return 删除环形搜索历史的结果
     */
    @DeleteMapping("/ring/delete")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String ringDelete(@RequestBody RingSearch ringSearch) {
        System.out.println("调用删除环形搜索历史接口成功");
        historyService.ringDelete(ringSearch.getRing_search_id());
        return "";
    }

    /**
     * 清空环形搜索历史
     *
     * @return 清空环形搜索历史的结果
     */
    @DeleteMapping("/ring/deleteAll")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String ringDeleteAll(@RequestBody User user) {
        System.out.println("调用清空环形搜索历史接口成功");
        historyService.ringDeleteAll(user.getAccount());
        return "";
    }

    /**
     * 获取所有林荫道搜索历史
     *
     * @return 所有林荫道搜索历史列表
     */
    @GetMapping("/treeLine/listAll")
    public List<TreeLineSearch> treeLineListAll(@RequestParam String account) {
        System.out.println(account);
        System.out.println("调用获取所有林荫道搜索历史成功");
        List<TreeLineSearch> treeLineSearches = historyService.treeLineListAll(account);
        for (TreeLineSearch cc : treeLineSearches) {
            System.out.println(cc.getTree_line_name());
        }
        return treeLineSearches;
    }

    /**
     * 删除林荫道搜索历史
     *
     * @return 删除林荫道搜索历史的结果
     */
    @DeleteMapping("/treeLine/delete")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String treeLineDelete(@RequestBody TreeLineSearch treeLineSearch) {
        System.out.println("调用删除林荫道搜索历史接口成功");
        historyService.treeLineDelete(treeLineSearch.getTree_line_search_id());
        return "";
    }

    /**
     * 清空林荫道搜索历史
     *
     * @return 清空林荫道搜索历史的结果
     */
    @DeleteMapping("/treeLine/deleteAll")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public String treeLineDeleteAll(@RequestBody User user) {
        System.out.println("调用清空林荫道搜索历史接口成功");
        historyService.treeLineDeleteAll(user.getAccount());
        return "";
    }
}
